#include <gtest/gtest.h>
#include "melon/client/thrift_client_pool.h"
#include "base/logging.h"
#include "CloudControlPushService.h"
#include "cloud_control/adapters/cloud_control_push_adapter.h"

using namespace cc;
using namespace std;

const int repeat_times = 1;
const int kThreadCount = 1;

void * ThreadFun(void * data) {

  for (int i=0; i<repeat_times; ++i) {

    int type = 1986;
//  int64_t pc_qid = 242736791;
//  string pc_body = "{'user_id':'123456','pc_mid':'8437834738','action': 'forbid','operate_items':[{'name':'百度管家','id':'baiduguanjia'},{'name':'豌豆荚','id':'wandoujia'}]}";
//  int pc_ret = CloudControlPushAdapter::Instance().PushToPc(pc_qid, type, pc_body, 3);
//  LOG_DEBUG(pc_ret);

//  string phone_key = "1521133145487f7f02c76f97626ffc5b";
    string phone_key = "bd3508b4f25d68d4db6d21704d17e14e";
    string phone_body = "{\"result\":\"success\", \"task_id\":\"25141\",\"phone_mid\":\"bd3508b4f25d68d4db6d21704d17e14e\", \"action\":\"uninstall\",\"business\":{\"softs\":[{'name': '百度云管家','id': '23232','status': 'success'},{'name': 'QQ','id': '12324','status': 'success'}], \"sum_size\":\"0\", \"time\":\"1\"}, \"pc_mid\":\"6e78238851ab5b30b13db8c60f2a5763\"}";
    int phone_ret = CloudControlPushAdapter::Instance().PushToPhone(phone_key, 1, phone_body, 3);
    LOG_DEBUG(phone_ret);

    phone_body = "{'result': 'success','task_id': '25142','phone_mid': 'bd3508b4f25d68d4db6d21704d17e14e','action': 'speed','business': {'speed_up': {'boot': '123'}},'pc_mid': '6e78238851ab5b30b13db8c60f2a5763'}";
    phone_ret = CloudControlPushAdapter::Instance().PushToPhone(phone_key, 1, phone_body, 3);
    LOG_DEBUG(phone_ret);

//  phone_body = "{'task_id':'111001','action':'uninstall','business':{'softs':[{'name':'qq','id':'213','status':'failed'},{'name':'baidu','id':'2223','status':'success'}], 'sum_size':'128M', 'time':'213214'}}";
//  phone_ret = CloudControlPushAdapter::Instance().PushToPhone(phone_key, type, phone_body, 3);
//  LOG_DEBUG(phone_ret);

//  phone_body = "{'task_id':'111001','action':'forbid','business':{'boots':[{'name':'qq','id':'213','status':'failed'},{'name':'baidu','id':'2223','status':'success'}], 'time':'121231'}}";
//  phone_ret = CloudControlPushAdapter::Instance().PushToPhone(phone_key, type, phone_body, 3);
//  LOG_DEBUG(phone_ret);

    sleep(1);
  }

  return NULL;
}

int main() {
  LOG_INIT("./logs/cloud_control_push_service_test.log", "DEBUG");

  pthread_t ts[kThreadCount];

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_create(&ts[i], NULL, ThreadFun, NULL);
  }

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_join(ts[i], NULL);
  }

  return 0;
}
